const mergeRoute = (route, menu) => {
  menu.forEach(item => {
    toRoute(item, route)
  })
}

const toRoute = function (item, route, parentUrl = '') {
  const {url, text} = item
  if (url) {
    route.unshift({
      path: `${parentUrl}${url}`,
      component: require(`@/pages${parentUrl}${url}/index.js`).default,
      title: text,
      auth: 'true'
    })
  }
  if (item.children && item.children.length) {
    for (let i = 0, len = item.children.length; i < len; i++) {
      toRoute(item.children[i], route, item.url)
    }
  }
}

export default mergeRoute
